<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>档案管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!--引入本地的css样式-->
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" name="name" placeholder="输入职位名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">应聘职位</label>
                    <div class="layui-input-block">
                        <input type="text" id="job_title" name="job_title" placeholder="输入职位名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">工作经验</label>
                    <div class="layui-input-block">
                        <input type="text" id="work_experience" name="work_experience" placeholder="输入职位名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">简历状态</label>
                    <div class="layui-input-inline">
                        <select name="recruitment_type" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="存档">存档</option>
                            <option value="推荐面试">推荐面试</option>
                            <option value="推荐二面">推荐二面</option>
                            <option value="推荐三面">推荐三面</option>
                            <option value="推荐三面">录用</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">登记时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="registration_time" id="registration_time" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" id="btn_search" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <!--表格主题部分-->
        <div class="layui-card-body">

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layuiadmin-btn-admin" lay-event="batchdel">批量删除</button>
                    <button class="layui-btn layuiadmin-btn-admin" lay-event="add" id="add_employee" data-type="add_employee">简历登记</button>
                </div>
            </script>

            <!--数据表格-->
            <table class="layui-hide" id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
                <a class="layui-btn layui-btn-xs" lay-event="registrationResults">面试结果登记</a>
                <a class="layui-btn layui-btn-xs" lay-event="employmentRegistration">录用登记</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>


        </div>
    </div>
</div>

<script src="../../static/js/jquery-3.6.0.min.js"></script>
<!--引入本地layui.js-->
<script src="../../static/layui/layui.js"></script>
<!--js-->
<script type="text/javascript">
    layui.config({
        base: '../../static/layui/layuiadmin/' //静态资源所在路径js
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //常规用法
        laydate.render({
            elem: '#registration_time'
        });

    });
    // layui.use('laydate', function() {
    //     var laydate = layui.laydate;
    //     //常规用法
    //     laydate.render({
    //         elem: '#expiration_date'
    //     });
    //
    // });
</script>

<script type="text/javascript">
    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        table.render({
            elem: '#LAY-user-back-manage'
            ,url:'/resume/queryResume'
            ,title: '简历数据表'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'resume_id', title:'简历ID', fixed: 'left', unresize: true, sort: true}
                ,{field:'name', title:'姓名',}
                ,{field:'sex', title:'性别',}
                ,{field:'graduate_school', title:'毕业院校',}
                ,{field:'education_background', title:'学历',}
                ,{field:'major', title:'专业',}
                ,{field:'job_title', title:'应聘职位名称',}
                ,{field:'work_experience', title:'工作经验',}
                ,{field:'registration_time', title:'登记时间',}
                ,{field:'recommend_the_interview', title:'简历状态',}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:300}

            ]]
            ,page: true
            ,limits:[5,10,15,20]
        });

        //搜索点击事件
        $("#btn_search").click(function () {
            var name = $("#name").val();
            var job_title = $("#job_title").val();
            var work_experience = $("#work_experience").val();
            var recommend_the_interview = $("#recommend_the_interview").val();
            var registration_time = $("#registration_time").val();
            //执行重载
            table.reload('LAY-user-back-manage', {
                url:'/recruitment/search',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    name: name,
                    job_title:job_title,
                    work_experience:work_experience,
                    recommend_the_interview:recommend_the_interview,
                    registration_time:registration_time
                }
            });
        });

        //监听行工具事件
        table.on('tool(LAY-user-back-manage)', function(obj){
            var data = obj.data;//选中的当前行的数据
            var data2=obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    //通过ajax实现真正的删除
                    $.ajax({
                        url:"/resume/delResume",
                        type:"post",
                        data:{id:data.resume_id},
                        dataType:"json",
                        success:function (res) {
                            layer.alert(res.msg);
                            obj.del();
                            layer.close(index);
                        }
                    })

                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑职务发布变更'
                    ,content: 'editresume.html'
                    ,area: ['450px', '550px']
                    ,maxmin:true
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var submitData = body.find('#myform').serialize();
                        //提交 Ajax 成功后，静态表单中的数据
                        $.ajax({
                            url:"/resume/updateResume",
                            type:"post",
                            data:submitData,
                            dataType:"json",
                            success:function (res) {
                                if(res.code == 200){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                if(res.code == 500){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                layer.close(index); //关闭弹层

                            }
                        })

                    }
                    ,success: function (layero, index) {//点击弹出框时，执行的函数。
                        var body = layer.getChildFrame('body', index);

                        //找到body中input输入框，向employee_name输入框中塞入选中行的值
                        body.find("input[name=resume_id]").val(data.resume_id);
                        body.find("input[name=job_title]").val(data.job_title);
                        body.find("input[name=job_code]").val(data.job_code);
                        body.find("input[name='job_classification']").val(data.job_classification);
                        body.find("input[name=name]").val(data.name);
                        body.find("select[name=sex]").val(data.sex);//
                        body.find("select[name=recruitment_type]").val(data.recruitment_type);//
                        body.find("input[name=email]").val(data.email);
                        body.find("input[name=phone]").val(data.phone);
                        body.find("input[name=registered_residence]").val(data.registered_residence);
                        body.find("input[name=address]").val(data.address);
                        body.find("input[name=political_landscape]").val(data.political_landscape);
                        body.find("input[name=id_number]").val(data.id_number);
                        body.find("input[name=graduate_school]").val(data.graduate_school);
                        body.find("select[name=education_background]").val(data.education_background);//
                        body.find("input[name=major]").val(data.major);
                        body.find("input[name=work_experience]").val(data.work_experience);
                        body.find("input[name=salary_requirement]").val(data.salary_requirement);
                        body.find("select[name=whether_in_office]").val(data.whether_in_office);//
                        body.find("select[name=fresh_graduate]").val(data.fresh_graduate);//
                        body.find("input[name=registration_time]").val(data.registration_time);
                        body.find("textarea[name=personal_resume]").val(data.personal_resume);
                        body.find("select[name=recommend_the_interview]").val(data.recommend_the_interview);//
                        body.find("input[name=referrer]").val(data.referrer);
                        body.find("input[name=the_recommended_time]").val(data.the_recommended_time);
                        body.find("textarea[name=recommended_Interview_advice]").val(data.recommended_Interview_advice);



                    }
                });
            // 面试结果登记
            }else if(obj.event === 'registrationResults'){
                $.ajax({
                    url:"/resume/queryRegistrationResults",
                    type:"post",
                    data:{id:data.resume_id},
                    dataType:"json",
                    success:function (res) {
                        data2=res.data;
                        console.assert(data2);
                    }
                });
                layer.open({
                    type: 2
                    ,title: '面试结果登记'
                    ,content: 'editRegistrationResults.html'
                    ,area: ['450px', '550px']
                    ,maxmin:true
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var submitData = body.find('#myform').serialize();
                        //提交 Ajax 成功后，静态表单中的数据
                        $.ajax({
                            url:"/resume/updateRegistrationResults",
                            type:"post",
                            data:submitData,
                            dataType:"json",
                            success:function (res) {
                                if(res.code == 200){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                if(res.code == 500){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                layer.close(index); //关闭弹层

                            }
                        })

                    }
                    ,success: function (layero, index) {//点击弹出框时，执行的函数。
                        var body = layer.getChildFrame('body', index);

                        //找到body中input输入框，向employee_name输入框中塞入选中行的值
                        body.find("input[name=resume_id]").val(data2.resume_id);
                        body.find("input[name=interview_result_id]").val(data2.interview_result_id);
                        body.find("select[name=recommend_the_interview]").val(data2.recommend_the_interview);
                        body.find("input[name='first_interviewer']").val(data2.first_interviewer);
                        body.find("input[name=first_time]").val(data2.first_time);
                        body.find("textarea[name=first_evaluation]").val(data2.first_evaluation);
                        body.find("input[name='second_interviewer']").val(data2.second_interviewer);
                        body.find("input[name=second_time]").val(data2.second_time);
                        body.find("textarea[name=second_evaluation]").val(data2.second_evaluation);
                        body.find("input[name='third_interviewer']").val(data2.third_interviewer);
                        body.find("input[name=third_time]").val(data2.third_time);
                        body.find("textarea[name=third_evaluation]").val(data2.third_evaluation);



                    }
                });
            }else if(obj.event === 'employmentRegistration') {
                $.ajax({
                    url: "/resume/employedRegistrationResults",
                    type: "post",
                    data: {id: data.resume_id},
                    dataType: "json",
                    success: function (res) {
                        data2 = res.data;

                    }
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(LAY-user-back-manage)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'batchdel':
                    var data = checkStatus.data;
                    if(data.length < 1){
                        layer.msg('未选中删除的数据');
                    }else{
                        //删除，通过ajax方式进行删除
                        layer.confirm('真的删除选中行的数据么', function(index){
                            var ids = new Array();
                            $.each(data,function (index,item) {
                                //循环遍历勾选数据，只将要删除数据的id号获取处理，塞给数组对象
                                ids.push(item.resume_id);
                            })
                            //通过ajax传递给后端
                            $.ajax({
                                url:"/resume/delResumes",
                                type:"post",
                                data:{ids:ids},
                                traditional:true,//单纯的传递数组，需要将其进行传统序列化操作
                                dataType:"json",
                                success:function (res) {
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 2000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                            })
                        });

                    }
                    break;
                case 'add':
                    layer.open({
                        type: 2
                        ,title: '简历登记'
                        ,content: 'addresume.html'
                        ,area: ['450px', '550px']
                        ,maxmin:true
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //var submitData = body.find('#myform').serialize();
                            var document1 = iframeWin.document;
                            var myformlist = document1.getElementById('myform');
                            var submitData = new FormData(myformlist);
                            //提交 Ajax 成功后，静态表单中的数据
                            $.ajax({
                                url:"/addResume",
                                type:"post",
                                data:submitData,
                                dataType:"json",
                                cache:false,
                                processData:false,
                                contentType:false,
                                success:function (res) {
                                    if(res.code == 200){
                                        layer.msg(res.msg, {
                                            offset: '15px'
                                            ,icon: 1
                                            ,time: 1000
                                        },function () {
                                            //刷新
                                            window.location.reload();
                                        });
                                    }
                                    if(res.code == 500){
                                        layer.msg(res.msg, {
                                            offset: '15px'
                                            ,icon: 1
                                            ,time: 1000
                                        },function () {
                                            //刷新
                                            window.location.reload();
                                        });
                                    }
                                    layer.close(index); //关闭弹层

                                }
                            })

                        }
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });


    });
</script>

</body>
</html>

